#include "../../types.hpp"
#include "../../math/math.hpp"
#include "../../render/program.hpp"

#include "program_utils.hpp"

#include <fstream>

using namespace std;
namespace raja
{
namespace utils
{

static std::string _load_file(const std::string &file_name)
{
	string str;

	fstream	fs;

	fs.open(file_name.c_str(), fstream::in | fstream::binary);
	if( fs.is_open() )
	{
		cout << "file: " << file_name << " is found" << endl;
		char ch;
		while(!fs.eof())
		{
			fs.read(&ch, 1);
			str += ch;
		}
		fs.close();
	}
	else
	{
		cout << "error loading file: " << file_name << endl;
	}

	return str;
}

///
/// create a render program from 2 files
/// @param vs_filename vertex shader file name
/// @param fs_filename fragment shader file name
/// @return render program
///
render::program* render_program_from_files(const std::string &vs_filename,
										   const std::string &fs_filename)
{
	// load the shaders
	string vs_str	= _load_file(vs_filename);
	string fs_str	= _load_file(fs_filename);

	return render::program::create(vs_str, fs_str);
}

}	// namespace utils
}	// namespace raja
